from rest_framework.views import APIView
from rest_framework.response import Response
from ..utils.spark_ai import SparkAIHandler

class SmartGuideView(APIView):
    def post(self, request):
        try:
            symptoms = request.data.get('symptoms')
            messages = request.data.get('messages', [])
            
            spark_handler = SparkAIHandler()
            result = spark_handler.generate_response(messages)
            
            return Response({
                'success': True,
                'result': result
            })
        except Exception as e:
            return Response({
                'success': False,
                'message': str(e)
            }, status=500)

class CheckModelConnectionView(APIView):
    def get(self, request):
        try:
            spark_handler = SparkAIHandler()
            test_message = [{'role': 'user', 'content': 'test connection'}]
            spark_handler.generate_response(test_message)
            return Response({'success': True})
        except Exception as e:
            return Response({
                'success': False,
                'message': str(e)
            })